/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-09-30 11:02:27
 * @filename : static/logic/nmm/src/views/myProfileBasic.js
 * @version : 
 * @description : 
 */

define(function(require, exports, module){

    var myProfileBasicView,userObj,
        mId = 'myProfileBasic',reRender = false,menuName = 'myProfileBasic',
        imglazyload = require('{component}imglazyload/zepto.imglazyload'),
        panel = require('{component}panel/zepto.panel'),
        tplN = require('{view}userNav.tpl'),
        tplS = require('{view}select.tpl'),
        tpl = require('{view}myProfileBasic.tpl');

    myProfileBasicView = Backbone.View.extend({

        template: _.template(tpl),
        templateS: _.template(tplS),
        templateN: _.template(tplN),

        bindEvt : function() {
            var tthis = this,dom = $('#'+mId);
           
            dom.find('.back').on('tap',function(e){
                window.location.href = '#myProfile/whole/custom2'; 
            });

            dom.find('.save').on('tap',function(e){
                var usr_id = userObj.account.usr_id;
                var obj = {
                    height_all : dom.find('#height_all').val(),
                    ethnicity : dom.find('#ethnicity').val(),
                    eyes : dom.find('#eyes').val(),
                    hair : dom.find('#hair').val(),
                    body : dom.find('#body').val()     
                };

                var callback = function(){
                    userObj.detail.basics.height = obj.height_all;
                    userObj.detail.basics.ethnicity = obj.ethnicity;
                    userObj.detail.basics.eyes_color = obj.eyes;
                    userObj.detail.basics.hair_color = obj.hair;
                    userObj.detail.basics.body_type = obj.body;
                    share.cacheUserInfo(usr_id,userObj);
                    window.location.href = '#myProfile/whole/custom2'; 
                }
                
                share.updateProfile(usr_id,callback,obj);
            });
        },      

        render: function (obj) {
            if (!share.checkPermission(true)){return;}; 
            share.reRender(reRender,mId);  
            userObj = share.getObjStorage(share.userInfo().usr_id);
            if ($('#'+mId).length < 1) { 
                $('body').append(this.template(lang));
                this.bindEvt(); 
            } else {
                $('#'+mId).css('display','block');
            }
            share.panel(panel,this.templateN,mId,menuName);
            this.heightRender();
            this.ethnicityRender();
            this.eyesRender();
            this.hairRender();
            this.bodyRender();
        },

        heightRender : function() {
            var select = share.getLocalStorage('ms_height');
            $('#'+mId).find('#height_all').html(this.templateS({obj : select, value : userObj.detail.basics.height}));
        },

        ethnicityRender : function() {
            var select = share.getLocalStorage('ms_ethnicity');
            $('#'+mId).find('#ethnicity').html(this.templateS({obj : select, value : userObj.detail.basics.ethnicity}));
        },

        eyesRender : function() {
            var select = share.getLocalStorage('ms_eyes');
            $('#'+mId).find('#eyes').html(this.templateS({obj : select, value : userObj.detail.basics.eyes_color}));
        },

        hairRender : function() {
            var select = share.getLocalStorage('ms_hair');
            $('#'+mId).find('#hair').html(this.templateS({obj : select, value : userObj.detail.basics.hair_color}));
        },

        bodyRender : function() {
            var select = share.getLocalStorage('ms_body');
            $('#'+mId).find('#body').html(this.templateS({obj : select, value : userObj.detail.basics.body_type}));
        },

    });
	module.exports = myProfileBasicView;
})

